package ysq.xyg.web.controller;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.web.model.po.WebSignUp;
import ysq.xyg.web.model.vo.WebSignUpVo;
import ysq.xyg.web.service.WebSignUpService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 业务模块-我要报名controller层
 *
 * @author shengQiang yu
 * @date 2019-4-25 16:05:25
 */
@RestController
public class WebSignUpController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(WebSignUpController.class);
    @Resource
    private WebSignUpService webSignUpService;

    private WebSignUp webSignUp;

    /**
     * 业务模块-我要报名模块统一跳转层
     *
     * @author shengQiang yu
     * @date 2019-04-25 16:42
     */
    @RequestMapping("/web/*")
    public Model goPage(Model model) {
        return model;
    }
    /**
     * list页面
     *
     * @param type 类型
     * @author shengQiang yu
     * @date 2019-4-25 16:05:25
     */
    @RequestMapping(value = "/webSignUp/listPage",method = RequestMethod.GET)
    public ModelAndView listPage(String type){
        ModelAndView view = new ModelAndView("/web/webSignUpList");
        view.addObject("type", type);
        return view;
    }
    /**
     * 分页查询
     *
     * @param webSignUpVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2019-4-25 16:05:25
     */
    @BaseLog(module = "业务模块",className = "我要报名",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webSignUp/page",method = RequestMethod.POST)
    public ReturnEntity page(WebSignUpVo webSignUpVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = webSignUpService.pageLeft(webSignUpVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-4-25 16:05:25
     */
    @RequestMapping(value = "/webSignUp/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id,String type){
        ModelAndView view = new ModelAndView("/web/webSignUpUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            webSignUp = webSignUpService.selectByPrimaryKey(id);
        }else{
            webSignUp=new WebSignUp();
            webSignUp.setType(type);
        }
        view.addObject("webSignUp", webSignUp);
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-4-25 16:05:25
     */
    @BaseLog(module = "业务模块",className = "我要报名",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webSignUp/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return webSignUpService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param webSignUpVo Vo对象
     * @author shengQiang yu
     * @date 2019-4-25 16:05:25
     */
    @BaseLog(module = "业务模块",className = "我要报名",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webSignUp/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,WebSignUpVo webSignUpVo) throws Exception {
        return webSignUpService.addOrUpdate(webSignUpVo,acceptCurrentUser(request));
    }
}